package com.ostrich.cloud.ostrichGoodsService.app.ApiImp;

import cn.hutool.core.bean.BeanUtil;
import com.ostrich.cloud.common.result.PageResult;
import com.ostrich.cloud.ostrichGoodsSercice.model.Dto.SalesDto;
import com.ostrich.cloud.ostrichGoodsSercice.model.param.AddSalesParam;
import com.ostrich.cloud.ostrichGoodsSercice.model.param.GetSalesParam;
import com.ostrich.cloud.ostrichGoodsService.app.component.Utlis;
import com.ostrich.cloud.ostrichGoodsService.client.SalesClient;
import com.ostrich.cloud.ostrichGoodsService.service.SalesService;
import com.ostrich.cloud.ostrichGoodsService.service.param.CreateSalesParam;
import com.ostrich.cloud.ostrichGoodsService.service.param.SelectSalesParam;
import org.aspectj.weaver.ast.Var;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
public class SalesApiImp implements SalesClient {
    @Resource
    private SalesService salesService;

    @Override
    public boolean addSales(AddSalesParam param) {

        CreateSalesParam createSalesParam = BeanUtil.copyProperties(param, CreateSalesParam.class);
        boolean bool=salesService.createSales(createSalesParam);
        return bool;

    }

    @Override
    public boolean putSales(Long orderNo) {

        boolean bool=salesService.updateSales(orderNo);
        return bool;

    }

    @Override
    public PageResult<SalesDto> getAllSalesDto(Integer current,Integer size) {

        PageResult<SalesDto> salesDto=salesService.getAllSalesDto(current,size);

        return salesDto;
    }

    @Override
    public PageResult<SalesDto> conditionsQuerySales(GetSalesParam param) {
        SelectSalesParam selectSalesParam = BeanUtil.copyProperties(param, SelectSalesParam.class);
        if(selectSalesParam.getBusinessmanId()==null){
            Integer businessmanId = Utlis.getParentId();
            selectSalesParam.setBusinessmanId(businessmanId);
        }
        PageResult<SalesDto> salesDtoPageResult=salesService.selectSalesCondition(selectSalesParam);


        return salesDtoPageResult;
    }
}
